package com.tuo.controller;

import com.tuo.beans.Detail;
import com.tuo.beans.Stopped;
import com.tuo.service.DetailService;
import com.tuo.service.StoppedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by tuo on 2016/1/9.
 */
@Controller
public class StoppedController {
    @Autowired
    StoppedService service;
    @Autowired
    DetailService detailService;

    @ResponseBody
    @RequestMapping("stopped")
    public Map<String, Object> stopped(long detailId) {
        Map<String, Object> map = new HashMap<String, Object>();
        Stopped stopped = new Stopped();
        stopped.setDetailId(detailId);
        List<Stopped> stoppeds = null;
        try {
            stoppeds = this.service.query(stopped);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        map.put("rows", stoppeds);
        return map;
    }

    @ResponseBody
    @RequestMapping("saveStopped")
    public Map<String, String> saveStopped(Stopped stopped) {
        Map<String, String> map = new HashMap<String, String>();
        try {
            //保存报停信息
            this.service.save(stopped);
            map.put("message", "success");
        } catch (Throwable e) {
            map.put("errorMsg", e.getMessage());
        }
        return map;
    }
}
